package com.tjtt.gwm.dao.impl;

import java.util.Map;

import com.tjtt.gwm.dao.YanfajianceShebeiDao;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;

public class YanfajianceShebeiDaoImpl  extends BaseHibernateDao implements YanfajianceShebeiDao{

	/*
	 * 查询研发检测流程设备列表
	 * wxj
	 */
	public PageResult queryYFJCShebei(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from GWM_YFJCFUZHUSHEBEI t where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.ID,t.TASKID,t.ZHUSHEBEIID,t.FUZHUSHEBEIID,t.FUZHUSHEBEINAME,t.SHEBEINAME,t.GUIGEXINGHAO," +
				"t.CHUCHANGNO,t.SHENGCHANCHANGJIA,t.GUANLIZHUANGTAI,t.YOUXIAOQI,t.JIANDINGZHUANGTAI" +
				" from GWM_YFJCFUZHUSHEBEI t  where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("taskId") && !"".equals(filterMap.get("taskId"))){
				queryString.append(" and t.TASKID = '"+filterMap.get("taskId")+"'");
				countString.append(" and t.TASKID = '"+filterMap.get("taskId")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	/*
	 * 查询所有设备列表
	 * wxj
	 */
	public PageResult queryEquipmentList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		
		StringBuffer queryString = new StringBuffer();	
		if(null!=filterMap && !filterMap.isEmpty()){
			if("1".equals(filterMap.get("type"))){//查询右侧已选列表
				countString.append("select count(*) from GWM_YFJCFUZHUSHEBEI y left join TDM_EQUIPMENT_MAIN t on t.id = y.ZHUSHEBEIID left join TDM_HETONG h on h.equ_main_id = t.id" +
					" left join TDM_MEASUREMENT_INFO j on j.equ_main_id = t.id where 1 = 1 ");
				queryString.append("select y.ZHUSHEBEIID,t.EQUIPMENT_NAME,t.EQUIPMENT_GGXH,t.EQUIPMENT_CCBH,t.EQUIPMENT_SCCJ,t.equipment_sb_state," +
					"j.EQUIPMENT_JDJZYXQ,j.EQUIPMENT_JDZT,t.EQUIPMENT_ORG_NAME,t.EQUIPMENT_CFD from GWM_YFJCFUZHUSHEBEI y left join TDM_EQUIPMENT_MAIN t on t.id = y.ZHUSHEBEIID left join TDM_HETONG h on h.equ_main_id = t.id" +
					" left join TDM_MEASUREMENT_INFO j on j.equ_main_id = t.id where 1 = 1 ");
				if(null!=filterMap.get("taskId") && !"".equals(filterMap.get("taskId"))){
					queryString.append(" and y.TASKID = '"+filterMap.get("taskId")+"'");
					countString.append(" and y.TASKID = '"+filterMap.get("taskId")+"'");
				}
				if(null!=filterMap.get("item_sample_id") && !"".equals(filterMap.get("item_sample_id"))){
					queryString.append(" and y.ITEM_SAMPLE_ID like '%,"+filterMap.get("item_sample_id")+",%'");
					countString.append(" and y.ITEM_SAMPLE_ID like '%,"+filterMap.get("item_sample_id")+",%'");
				}
			}else{//查询左侧列表
				countString.append("select count(*) from TDM_EQUIPMENT_MAIN t left join TDM_HETONG h on h.equ_main_id = t.id" +
						" left join TDM_MEASUREMENT_INFO j on j.equ_main_id = t.id where PARENT_ID is null ");
				queryString.append("select t.id,t.EQUIPMENT_NAME,t.EQUIPMENT_GGXH,t.EQUIPMENT_CCBH,t.EQUIPMENT_SCCJ,t.equipment_sb_state," +
						"j.EQUIPMENT_JDJZYXQ,j.EQUIPMENT_JDZT,t.EQUIPMENT_ORG_NAME,t.EQUIPMENT_CFD from TDM_EQUIPMENT_MAIN t left join TDM_HETONG h on h.equ_main_id = t.id" +
						" left join TDM_MEASUREMENT_INFO j on j.equ_main_id = t.id where PARENT_ID is null ");
				if(null!=filterMap.get("shebeiids") && !"".equals(filterMap.get("shebeiids"))){
					queryString.append(" and t.id not in ("+filterMap.get("shebeiids")+")");
					countString.append(" and t.id not in ("+filterMap.get("shebeiids")+")");
				}
				if(null!=filterMap.get("orgid") && !"".equals(filterMap.get("orgid")) && !"1".equals(filterMap.get("orgid")) ){
					queryString.append(" and (t.EQUIPMENT_ORG_ID = '"+filterMap.get("orgid")+"' or t.EQUIPMENT_ORG_ID in (select o.org_id from SYS_ORGANIZATION o where o.org_parent_id="+filterMap.get("orgid")+"))");
					countString.append(" and (t.EQUIPMENT_ORG_ID = '"+filterMap.get("orgid")+"' or t.EQUIPMENT_ORG_ID in (select o.org_id from SYS_ORGANIZATION o where o.org_parent_id="+filterMap.get("orgid")+"))");
				}
			}
			if(null!=filterMap.get("shebeiname") && !"".equals(filterMap.get("shebeiname"))){
				queryString.append(" and t.EQUIPMENT_NAME like '%"+filterMap.get("shebeiname")+"%'");
				countString.append(" and t.EQUIPMENT_NAME like '%"+filterMap.get("shebeiname")+"%'");
			}
			if(null!=filterMap.get("guigexinghao") && !"".equals(filterMap.get("guigexinghao"))){
				queryString.append(" and t.EQUIPMENT_GGXH like '%"+filterMap.get("guigexinghao")+"%'");
				countString.append(" and t.EQUIPMENT_GGXH like '%"+filterMap.get("guigexinghao")+"%'");
			}
			if(null!=filterMap.get("chuchangno") && !"".equals(filterMap.get("chuchangno"))){
				queryString.append(" and t.EQUIPMENT_CCBH like '%"+filterMap.get("chuchangno")+"%'");
				countString.append(" and t.EQUIPMENT_CCBH like '%"+filterMap.get("chuchangno")+"%'");
			}
			if(null!=filterMap.get("bumen") && !"".equals(filterMap.get("bumen"))){
				queryString.append(" and t.EQUIPMENT_ORG_ID = '"+filterMap.get("bumen")+"'");
				countString.append(" and t.EQUIPMENT_ORG_ID = '"+filterMap.get("bumen")+"'");
			}
			if(null!=filterMap.get("didian") && !"".equals(filterMap.get("didian"))){
				queryString.append(" and t.EQUIPMENT_CFD like '%"+filterMap.get("didian")+"%'");
				countString.append(" and t.EQUIPMENT_CFD like '%"+filterMap.get("didian")+"%'");
			}
			if(null!=filterMap.get("shebeistate") && !"".equals(filterMap.get("shebeistate"))){
				queryString.append(" and t.equipment_sb_state like '%"+filterMap.get("shebeistate")+"%'");
				countString.append(" and t.equipment_sb_state like '%"+filterMap.get("shebeistate")+"%'");
			}
			if(null!=filterMap.get("changjia") && !"".equals(filterMap.get("changjia"))){
				queryString.append(" and t.equipment_sb_state like '%"+filterMap.get("changjia")+"%'");
				countString.append(" and t.equipment_sb_state like '%"+filterMap.get("changjia")+"%'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	/*
	 * 查询辅助设备
	 * wxj
	 */
	public PageResult queryFuzhuShebei(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EQUIPMENT_MAIN t where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t.EQUIPMENT_NAME,t.EQUIPMENT_GGXH,t.EQUIPMENT_CCBH,t.EQUIPMENT_SCCJ,t.equipment_sb_state," +
						"j.EQUIPMENT_JDJZYXQ,j.EQUIPMENT_JDZT,t.EQUIPMENT_ORG_NAME,t.EQUIPMENT_CFD from TDM_EQUIPMENT_MAIN t left join TDM_HETONG h on h.equ_main_id = t.id" +
						" left join TDM_MEASUREMENT_INFO j on j.equ_main_id = t.id where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("shebeiId") && !"".equals(filterMap.get("shebeiId"))){
				queryString.append(" and t.PARENT_ID = '"+filterMap.get("shebeiId")+"'");
				countString.append(" and t.PARENT_ID = '"+filterMap.get("shebeiId")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	/*
	 * 查询研发检测流程辅助设备
	 * wxj
	 */
	public PageResult queryYFJCFuzhuShebei(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EQUIPMENT_MAIN t where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t.EQUIPMENT_NAME,t.EQUIPMENT_GGXH,t.EQUIPMENT_CCBH,t.EQUIPMENT_SCCJ,t.equipment_sb_state," +
						"j.EQUIPMENT_JDJZYXQ,j.EQUIPMENT_JDZT,t.EQUIPMENT_ORG_NAME,t.EQUIPMENT_CFD from TDM_EQUIPMENT_MAIN t left join TDM_HETONG h on h.equ_main_id = t.id" +
						" left join TDM_MEASUREMENT_INFO j on j.equ_main_id = t.id where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("fuzhushebeiId") && !"".equals(filterMap.get("fuzhushebeiId"))){
				queryString.append(" and t.id in ("+filterMap.get("fuzhushebeiId")+")");
				countString.append(" and t.id in ("+filterMap.get("fuzhushebeiId")+")");
			}else{
				queryString.append(" and t.id in ('')");
				countString.append(" and t.id in ('')");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	/*
	 * 查询样品项目设备列表
	 * wxj
	 */
	public PageResult queryYPXMEquipmentList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from GWM_YFJCFUZHUSHEBEI t where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.ID,t.TASKID,t.ZHUSHEBEIID,t.FUZHUSHEBEIID,t.FUZHUSHEBEINAME,t.SHEBEINAME,t.GUIGEXINGHAO," +
				"t.CHUCHANGNO,t.SHENGCHANCHANGJIA,t.GUANLIZHUANGTAI,t.YOUXIAOQI,t.JIANDINGZHUANGTAI" +
				" from GWM_YFJCFUZHUSHEBEI t  where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("taskId") && !"".equals(filterMap.get("taskId"))){
				queryString.append(" and t.TASKID = '"+filterMap.get("taskId")+"'");
				countString.append(" and t.TASKID = '"+filterMap.get("taskId")+"'");
			}
			if(null!=filterMap.get("item_sample_id") && !"".equals(filterMap.get("item_sample_id"))){
				queryString.append(" and t.ITEM_SAMPLE_ID like '%,"+filterMap.get("item_sample_id")+",%'");
				countString.append(" and t.ITEM_SAMPLE_ID like '%,"+filterMap.get("item_sample_id")+",%'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
}
